package cn.zhf.shop.service.impl;

import cn.zhf.shop.entity.Message;
import cn.zhf.shop.entity.Stage;
import cn.zhf.shop.mapper.StageMapper;
import cn.zhf.shop.service.StageService;
import cn.zhf.shop.utils.OrderUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Service
public class StageServiceImpl implements StageService {

    @Resource
    private StageMapper stageMapper;


    @Override
    public Message<?> insert(Stage s) {
        String id=OrderUtil.genOrderId();

        s.setId(id);

        s.setCreateDate(new Date());
        return stageMapper.insert(s) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<Stage> getStageByOrderId(String orderId) {
        Stage stage = stageMapper.selectByOrderId(orderId);
        return stage == null ? Message.fail(null) : Message.success(null).add(stage);
    }

    @Override
    public Message<List<Stage>> getStageByState(Integer state) {
        return null;
    }

    @Override
    public Message<?> updateState(String orderId,Integer state) {
        return stageMapper.updateStateByOrderId(state, orderId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<List<Stage>> getAllStage() {
        return Message.success(null).add(stageMapper.selectAll());
    }

    @Override
    public Stage getStageByOrderId2(String orderId) {
        return stageMapper.selectByOrderId(orderId);
    }


}
